LibHTTP Examples
Series of simple real-world tests/examples to demonstrate the use of LibHTTP.
/load -rs libhttp_examples.mrc
and run /http_test_1
through /http_test_8
All tests echo their output to status window.
Exported Alias Summary | |
---|---|
void
|
http_test_1() Example 1: Get RSS feed from slashdot and echo the headlines to status window |
void
|
http_test_2() Example 2: Check www.mirc.com for latest mirc release |
void
|
http_test_3() Example 3: Downloads latest servers.ini |
void
|
http_test_4() Example 4: Test 3 with a twist - redirection |
void
|
http_test_5() Example 5: Retrieve password protected file |
void
|
http_test_6() Example 6: Error handling, attempt to download a non-existing file |
void
|
http_test_7() Example 7: Error handling, attempt connecting to invalid host |
void
|
http_test_8() Example 8: Simple URL parsing test |
String
|
parse_url(url) Needed for test_8 |
Local Alias Summary |
---|
Event Summary |
---|
on *:sockread:SLASHDOT { * |
on *:sockread:MIRCVER { * |
on *:sockread:SERVERSINI { * |
on *:sockclose:SERVERSINI { * |
on *:sockread:SERVERSINI2 { * |
on *:sockclose:SERVERSINI2 { * |
on *:sockread:SECRET: { * |
on *:signal:HttpErr_BADFILE: { * |
on *:sockread:BADFILE { * |
on *:signal:HttpErr_BADHOST: { * |
on *:sockread:BADHOST { * |
on *:UNLOAD: { *Remove server_ini_demo_txt created in tests 2 & 3 |
void http_test_1()
Example 1: Get RSS feed from slashdot and echo the headlines to status window. The regex just extracts the string between <title>...</title>.
void http_test_2()
Example 2: Check www.mirc.com for latest mirc release. This could of course break at any time if the site maintainers decide to change the layout. No need to complain if that happens, it is just an example...
void http_test_3()
Example 3: Downloads latest servers.ini. The file is saved in your mircdir as servers.ini.demo.txt (so it won't overwrite your real servers.ini). This is a static file so the server knows and tells us the filesize, meaning it's possible to have a progress indicator using $httpsock. For dynamic content the filesize is usually not known in advance, so no way to have percentage indicator.
void http_test_4()
Example 4: Test 3 with a twist - redirection. Instead of going directly to mirc.co.uk, do "I'm feeling lucky" search on google. The search redirects to the correct address, and LibHTTP automatically follows it.
void http_test_5()
Example 5: Retrieve password protected file. The file is there "for now", some day I'll remove it and this test will stop working. Also shows how to guard against making duplicate requests by using $sockfree(...).
void http_test_6()
Example 6: Error handling, attempt to download a non-existing file. Server returns the 404 error.
void http_test_7()
Example 7: Error handling, attempt connecting to invalid host. The error manifests in a slightly different way if user has set to use a proxy. Connection to the proxy is possible, but obviously the proxy can't fullfill the request so it returns an error (usually code 500).
void http_test_8()
Example 8: Simple URL parsing test. The $parse_url alias used for this is an exact copy of LibHTTP's URL parser, lhttp_parse_url
. lhttp_parse_url is a local alias of LibHTTP, which is why this test cannot use it directly.
String parse_url(url)
Needed for test_8.
url
-